import 'package:flutter/material.dart';

class Ball {
  double aX; //加速度
  double aY; //加速度Y
  double vX; //速度X
  double vY; //速度Y
  double x; //点位X
  double y; //点位Y
  Color color; //颜色
  double r; //小球半径

  Ball({
    this.x = 0,
    this.y = 0,
    this.color,
    this.r = 10,
    this.aX = 0,
    this.aY = 0,
    this.vX = 0,
    this.vY = 0,
  });
}

class RunBallView extends CustomPainter {
  Ball _ball;
  Rect _area; // 运动区域
  Paint mPaint; // 主画笔
  Paint bgPaint; // 背景画笔

  RunBallView(this._ball, this._area) {
    mPaint = new Paint();
    bgPaint = new Paint()..color = Color.fromARGB(148, 198, 246, 248);
  }

  @override
  void paint(Canvas canvas, Size size) {
    canvas.drawRect(_area, bgPaint);
    _drawBall(canvas, _ball);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }

  void _drawBall(Canvas canvas, Ball ball) {
    canvas.drawCircle(
      Offset(ball.x, ball.y),
      ball.r,
      mPaint..color = ball.color,
    );
  }
}
